package com.thingsgrid.device.monitor.controller;
import com.thingsgrid.device.entity.Product;
import com.thingsgrid.device.entity.ProductType;
import com.thingsgrid.device.monitor.service.IRunAnalyzeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.LinkedHashMap;
import java.util.List;

/**
 *运行分析
 */
@AllArgsConstructor
@RestController
@RequestMapping("/run_classify")
@Api(value = "设备运行分析", tags = "设备运行分析")
public class RunAnalyzeController {

	private IRunAnalyzeService runAnalyzeService;

	/**
	 * 产品类型
	 * @return
	 */
	@GetMapping("/classify")
	@ApiOperation(value = "查询产品类型", notes = "查询产品类型", position = 1)
	public R<List<ProductType>> classify(){
		List<ProductType> productTypeList = runAnalyzeService.selectclassify();
		return R.data(productTypeList);
	}

	/**
	 * 根据productTypeId查询关联的产品名称
	 */
	@PostMapping("/findById")
	@ApiOperation(value = "根据id查询产品", notes = "根据id查询产品", position =2)
	public R<List<Product>> findById(@RequestParam String productTypeId){
		List<Product> productList = runAnalyzeService.findById(productTypeId);
		return R.data(productList);
	}
	/**
	 *运行分析
	 * @return
	 */
	@PostMapping("count_device")
	@ApiOperation(value = "根据Id查询设备在线数量", notes = "传入productId和selectTime", position =3)
	public R<LinkedHashMap<String, Integer>> countOnlieDeviceById(@RequestParam String productId, @RequestParam Integer selectTime) throws ParseException {
		LinkedHashMap<String, Integer> map = runAnalyzeService.countOnlieDeviceById(productId,selectTime);
		return R.data(map);
	}
}
